package com.brkj.util;

import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.view.View;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;
import net.tsz.afinal.FinalBitmap;

import com.nostra13.universalimageloader.core.ImageLoader;

import android.graphics.Bitmap;
import android.widget.ImageView;

public class ImgShow {

	public static FinalBitmap headFb;
	public static FinalBitmap fb;
    public static ImageLoader imageLoader;

//	public static void display(ImageView view,  String url){
//		if(url == null){
//			return;
//		}
//		ImageLoader.getInstance().displayImage(url.replace('\\', '/'), view);
//	}
	
	public static void displayHead(ImageView view,  String url){
		if(url == null){
			return;
		}
		
//		headFb = FinalBitmap.create(MyApplication.getContext(), ConstAnts.HEADIMG_DIR);
		headFb = FinalBitmap.create(MyApplication.getContext());
		headFb.display(view, url);
	}
	
	public static void display(ImageView view,  String url){
		if(url == null){
			return;
		}
		
//		fb = FinalBitmap.create(MyApplication.getContext());
////		fb = FinalBitmap.create(MyApplication.getContext(), ConstAnts.IMG_CATCH_DIR);
//		fb.display(view, url.replace('\\', '/'));

        if(imageLoader == null){
            imageLoader = ImageLoader.getInstance();
        }
        imageLoader.displayImage(url.replace('\\', '/'), view);

	}
	
	public static void display(View view,  String url){
		if(url == null){
			return;
		}

		fb = FinalBitmap.create(MyApplication.getContext());
//		fb = FinalBitmap.create(MyApplication.getContext(), ConstAnts.IMG_CATCH_DIR);
		fb.display(view, url.replace('\\', '/'));

	}

	public static void display(ImageView view,  String url, final int  laodfailBitmapID){
		if(url == null){
			return;
		}
		
//		fb = FinalBitmap.create(MyApplication.getContext(), ConstAnts.IMG_CATCH_DIR);
//		fb = FinalBitmap.create(MyApplication.getContext());
////		fb.display(view, url.replace('\\', '/'));
//		fb.display(view, url.replace('\\', '/'), null, laodfailBitmap);

        if(imageLoader == null){
            imageLoader = ImageLoader.getInstance();
        }
        imageLoader.displayImage(url.replace('\\', '/'), view, new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String s, View view) {

            }

            @Override
            public void onLoadingFailed(String s, View view, FailReason failReason) {
                ((ImageView)view).setImageResource(laodfailBitmapID);
            }

            @Override
            public void onLoadingComplete(String s, View view, Bitmap bitmap) {

            }

            @Override
            public void onLoadingCancelled(String s, View view) {

            }
        });

	}

}
